[#include "/includes/_layout.html"/]
[@layout]
<div class="wrapper wrapper-content">

	<div class="row animated fadeInLeft">
	
	[#include "/includes/menu-interaction.html" /]
	
	<div class="col-sm-11">
	<div class="row content-tabs">
		<nav class="page-tabs J_menuTabs">
	       <div class="page-tabs-content" style="margin-left: 0px;">
	           <a href="${webctx}/qiandao/add" class="J_menuTab">签到设置</a>
		       <a href="${webctx}/qiandao" class="J_menuTab active">签到管理</a>
		       <a href="${webctx}/qiandao/stat" class="J_menuTab">数据统计 </a>
	       </div>
	   	</nav>
	</div>
<!-- 	<div class="tabs-container row" style="padding-top: 12px;">
        <ul class="nav nav-tabs">
            <li><a href="${webctx}/qiandao/add">签到设置</a></li>
			<li class="active"><a href="${webctx}/qiandao">签到管理</a></li>
			<li><a href="${webctx}/qiandao/stat">数据统计</a></li>
        </ul>
    </div> -->
   	<!-- <div class="alert alert-success">
		在活动有效时间范围内，买家可以在手机淘宝参与签到，签到规则自由设置
	</div> -->
    <div id="tableList" class="row ibox-content" style="padding-top: 10px;">
		<table class="table-striped" width="100%" border="0" cellspacing="1" cellpadding="0">
			<tr>
				<td colspan="3" style="text-align: left;">&nbsp;&nbsp;
					<input type="text" name="q_pond_txt" id="q_pond_txt" class="input-text"
						style="width:190px; color:#DFDFDF" value="输入签到名称" 
						onfocus="if(this.value=='输入签到名称'){this.value=''};this.style.color='black';" 
						onblur="if(this.value==''||this.value=='输入签到名称'){this.value='输入签到名称';this.style.color='#DFDFDF';}"/>
					<!-- <select id="a_status_sel" style="width: 102px">
						<option value="-1" selected="selected">全部</option>
						<option value="3">进行中</option>
						<option value="2">已结束</option>
					</select>  -->
					<button id="myqueryBtn" class="btn btn-success">查询</button>
				</td>
			</tr>
		</table>
		<div id="qiandaoToolsbar" class="panel-body">
			<div id="pager" class="jqpager" style="margin-bottom: 1px;"></div>
			<!-- <div style="float: left;">
				<button id="myqiandaoDelBtn" class="btn btn-info">批量删除</button>
			</div> -->
		</div>
		<table class="table table-striped table-bordered bootstrap-datatable datatable" id="mainTable" border="0">
			<thead>
				<tr>
					<th>
						<input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/>
					</th>
					<th>
						<span style="vertical-align: middle;">&nbsp;&nbsp;活动名称</span>
					</th>
					<th>状态</th>
					<!-- <th>参与人数</th> -->
					<th>开始时间</th>
					<th>结束时间</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody class="qiandaoLotGrid">
			</tbody>
		</table>
	</div>        	
</div>
</div>
</div>
<!-- 模板开始 -->
<script type="text/template" id="qiandao_table_tr_tpl">
		<tr class="package">
			<td>
				<input type="checkbox" class="commchk" id="checkbox_{id}" style="margin-right: 4px; vertical-align: middle;"/>
			</td>
			<td>
				<span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">{qiandaoName}</span>
				<span style="text-align: right;float: right;">
					<i wl="{wirlessUrl}" qc="{qrCode}" class="fa fa-qrcode"></i>
				</span>
			</td>
			<td>
				<span class="label label-success" style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">{status}</span>
			</td>
			<td><span>{startDate}</span></td>
			<td><span>{endDate}</span></td>
			<td>
				&nbsp;<a id="edit_{id}" href="javascript:void(0)" style="text-decoration: underline;">编辑</a>
				&nbsp;<a id="del_{id}" href="javascript:void(0)" style="text-decoration: underline;">删除</a>
			</td>
		</tr>
</script>
<script type="text/template" id="table_noresult_tr_tpl">
	<tr class="package">
			<td class="center" colspan="6">
				没有结果集，现在去创建吧，
				<a href="${webctx}/qiandao/add" style="text-decoration: underline;">去创建</a>
			</td>
		</tr>
</script>
[/@layout]
<script type="text/javascript">
	var qname = "";
	$(document).ready(function() {
	    $("#myqueryBtn").click(function(){
	    	qname = $("#q_pond_txt").val() == "输入签到名称" ? "" : $("#q_pond_txt").val();
	    	searchQiandaos();
	    });
	    //批量删除
	    $("#myqiandaoDelBtn").click(function(){
	    	var count = TBatch.getCheckedCount();
	    	if(count ==0){
	    		obz.showMessage("请选择一个活动");
	    	}else{
	    		obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function(){
	    			var ids = TBatch.getChecked();
		    		obz.ajaxJson(obz.ctx + "/qiandao/del", {ids: ids}, function(resp){
		    			if(resp.code==200){
		    				searchQiandaos();	
		    			}
		    		});
	    		});
	    	}
	    });
	    
        searchQiandaos();
	});
	
	var pageClick = function(pageNo) {
		searchQiandaos(pageNo);
	}
	
	var searchQiandaos = function(currPage){
		var params = {};
		//其他查询条件
		if(currPage){
			params.page = currPage;
		}
		params.qname = qname;
		params.type = $("#a_type_sel").val();
		params.status = $("#a_status_sel").val();
		
		$("#mainTable").mask("加载中...");
		var url = obz.ctx + "/qiandao/list";
		obz.ajaxJson(url, params, function(resp){
			$("#mainTable").unmask();
			var result = resp.data;
			$(".qiandaoLotGrid").empty();
			if(currPage){
				$("#pager").pager({ pagenumber:currPage, recordcount:result.totalRow, pagesize:result.pageSize, recordtext:'共 {0} 页, {1} 条记录', buttonClickCallback: pageClick });
			}else{
				$("#pager").pager({ recordcount:result.totalRow, pagesize:result.pageSize, recordtext:'共 {0} 页, {1} 条记录', buttonClickCallback: pageClick });	
			}
			var dataList = result.list;
			if(dataList.length>0){
				for(var i=0;i<dataList.length;i++){
					var _row = dataList[i];
					var trHtml = obz.dataTemplate4obj($("#qiandao_table_tr_tpl").html(), _row);
					$(".qiandaoLotGrid").append(trHtml);
					obz.showQrcode(_row.wirlessUrl);
				}
				TBatch.checkCheckbox();
				TBatch.initCheckboxClick();
				TBatch.initOptEvent(ActivityTableOpt.init());
			}else{
				$(".qiandaoLotGrid").append($("#table_noresult_tr_tpl").html());
			}
		});
	}
	
	//=============================表格操作事件开始=============================================
	var ActivityTableOpt = {
		edit : function(param){
			var id = param[1];
			location.href = obz.ctx + "/qiandao/add/"+id;
		}, 
		del : function(param){
			obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function(){
    			var ids = param[1];
	    		obz.ajaxJson(obz.ctx + "/qiandao/del", {ids: ids}, function(resp){
	    			if(resp.code==200){
	    				searchQiandaos();	
	    			}
	    		});
    		});
			return false;
		},
		init : function(){
			var optArray = new Array();
			optArray.push(this.edit);
			optArray.push(this.del);
			return optArray;
		}
	}	
	//=============================表格操作事件结束=============================================
</script>
<script>
Template.init("#menu-qiandao");
Template.initSecond("#menu-Signin");
</script>